/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.sonar.util.ui.pans;

import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;

/**
 *
 * @author bennyl
 */
public abstract class DataView<T> {

    private JPanel dataContainer;
    private T model = null;

    public DataView(JPanel dataContainer) {
        this.dataContainer = dataContainer;
    }

    public T getModel() {
        return model;
    }

    public void setModel(T model) {
        this.model = model;
        dataContainer.removeAll();
        syncToModel();
    }

    protected abstract void syncToModel();

    public void showError(Exception ex) {
        dataContainer.removeAll();
        dataContainer.add(new ErrorPanel(ex), BorderLayout.CENTER);
        dataContainer.revalidate();
    }

    public JPanel getComponent() {
        return dataContainer;
    }

    public void showLoading() {
        dataContainer.removeAll();
        dataContainer.add(new LoadingPanel(), BorderLayout.CENTER);
        dataContainer.revalidate();
    }
}
